package org.diffshop.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.diffshop.ware.vo.MergePurchaseDetailVO;
import org.diffshop.ware.vo.PurchaseDoneVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.diffshop.ware.entity.WmsPurchaseEntity;
import org.diffshop.ware.service.WmsPurchaseService;
import org.diffshop.common.utils.PageUtils;
import org.diffshop.common.utils.R;



/**
 * 采购信息
 *
 * @author tjf
 * @date 2024-05-08 16:09:54
 */
@RestController
@RequestMapping("ware/wmspurchase")
public class WmsPurchaseController {
    @Autowired
    private WmsPurchaseService wmsPurchaseService;
    /**
     * 完成采购单
     * @param purchaseDoneVO
     * @return
     */
    @PostMapping("/done")
    public R done(@RequestBody PurchaseDoneVO purchaseDoneVO){
        wmsPurchaseService.done(purchaseDoneVO);

        return R.ok();
    }

    /**
     * 领取采购单
     * @param purchaseIds
     * @return
     */
    @PostMapping("/receive")
    public R receive(@RequestBody List<Long> purchaseIds){
        wmsPurchaseService.receive(purchaseIds);

        return R.ok();
    }

    /**
     * 查询未领取的采购单
     * @return
     */
    @GetMapping("/unreceive/list")
    public R queryPageUnreceivePurchases(@RequestParam Map<String, Object> params){
        PageUtils page = wmsPurchaseService.queryPageUnreceivePurchases(params);

        return R.ok().put("page", page);
    }

    /**
     * 采购需求合并到采购单
     * @return
     */
    @PostMapping("/merge")
    public R merge(@RequestBody MergePurchaseDetailVO mergePurchaseDetailVO){
        wmsPurchaseService.mergePurchaseDetail(mergePurchaseDetailVO);

        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wmsPurchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		WmsPurchaseEntity wmsPurchase = wmsPurchaseService.getById(id);

        return R.ok().put("purchase", wmsPurchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody WmsPurchaseEntity wmsPurchase){
		wmsPurchaseService.save(wmsPurchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody WmsPurchaseEntity wmsPurchase){
		wmsPurchaseService.updateById(wmsPurchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		wmsPurchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
